﻿using System;
using Script.EnemySystem.EnemyState;
using UnityEngine;

/// <summary>
/// 怪物基础信息
/// </summary>
[Serializable]
public class EnemyData
{
    public BaseData MaxHealth { get; set; } = new BaseData();
    public BaseData Hp { get; set; } = new BaseData();
    public BaseData MoveSpeed { get; set; } = new BaseData();
    public BaseData FollowSpeed { get; set; } = new BaseData();
    public BaseData Damage { get; set; } = new BaseData();
    public EnemyState State { get; set; }
    public BaseData MeleeAttackDistance { get; set; } = new BaseData();
    public BaseData RangedAttackDistance { get; set; } = new BaseData();
    public BaseData BackInterpolation { get; set; } = new BaseData();
    
    public TimeData TimeData { get; set; } = new TimeData();
    
    /// <summary>
    /// 技能冷却时间
    /// </summary>
    public BaseData[] StateColdDown
    {
        get;
        set;
    }
    
    public EnemyData() {
        
        StateColdDown = new BaseData[10];
        for (int i = 0; i < StateColdDown.Length; i++)
        {
            StateColdDown[i] = new BaseData(0);
        }
        
        State = EnemyState.Idle;
    }

    public EnemyData(float hp, float maxHealth, float moveSpeed, float followSpeed, float damage, float rangedAttackDistance, float meleeAttackDistance, float backInterpolation, float localTimeScale = 1)
    {
        TimeData = new TimeData(localTimeScale);
        Hp = new BaseData(hp);
        MaxHealth = new BaseData(maxHealth);
        MoveSpeed = new BaseData(moveSpeed);
        FollowSpeed = new BaseData(followSpeed);
        Damage = new BaseData(damage);
        MeleeAttackDistance = new BaseData(meleeAttackDistance);
        RangedAttackDistance = new BaseData(rangedAttackDistance);
        BackInterpolation = new BaseData(backInterpolation);
        
        StateColdDown = new BaseData[10];
        for (int i = 0; i < StateColdDown.Length; i++)
        {
            StateColdDown[i] = new BaseData(0);
        }
        
    }


    public EnemyData Plus(EnemyData data2)
    {
        TimeData.Plus(data2.TimeData);
        
        MoveSpeed += data2.MoveSpeed;
        MaxHealth += data2.MaxHealth;
        Damage += data2.Damage;
        Hp += data2.Hp;
        FollowSpeed -= data2.FollowSpeed;
        RangedAttackDistance += data2.RangedAttackDistance;
        MeleeAttackDistance += data2.MeleeAttackDistance;
        BackInterpolation += data2.BackInterpolation;
        return this;
    }

    public EnemyData Minus(EnemyData data2)
    {
        TimeData.Minus(data2.TimeData);
        
        MoveSpeed -= data2.MoveSpeed;
        MaxHealth -= data2.MaxHealth;
        Damage -= data2.Damage;
        Hp -= data2.Hp;
        FollowSpeed -= data2.FollowSpeed;
        RangedAttackDistance -= data2.RangedAttackDistance;
        MeleeAttackDistance -= data2.MeleeAttackDistance;
        BackInterpolation -= data2.BackInterpolation;
        return this;
    }
    
}
    